package com.sxt.sys.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sxt.sys.domain.News;
import com.sxt.sys.mapper.NewsMapper;
import com.sxt.sys.service.NewsService;
import com.sxt.sys.utils.DataGridView;
import com.sxt.sys.vo.NewsVo;

@Service
@Transactional
public class NewsServiceImpl implements NewsService {
	@Autowired
	private NewsMapper newsMapper;

	@Override
	public DataGridView queryAllNews(NewsVo newsVo) {
		Page<Object> page = PageHelper.startPage(newsVo.getPage(),
				newsVo.getRows());
		List<News> list = this.newsMapper.queryAllNews(newsVo);
		System.out.println(page.getTotal());
		System.out.println(list.size());
		
	
		return new DataGridView(page.getTotal(), list);
	}

	@Override
	public void addNews(NewsVo newsVo) {
		// TODO Auto-generated method stub
		newsMapper.insertSelective(newsVo);
	}

	@Override
	public void updateNews(NewsVo newsVo) {
		// TODO Auto-generated method stub
		newsMapper.updateByPrimaryKeySelective(newsVo);
	}

	@Override
	public void deleteNews(NewsVo newsVo) {
		// TODO Auto-generated method stub
		newsMapper.deleteByPrimaryKey(newsVo.getId());
	}
}
